<?php
    namespace backend\models;

    use yii\base\Model;
    use yii\web\UploadedFile;

    class Lunboimg extends Model{
        /**
         * @var UploadedFile
         */
        public $imageFile;

        public function rules()
        {
            //编写允许上传图片类型的规则
            return [
                [['imageFile'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg'],
            ];
        }

        public function upload()
        {
            if ($this->validate()) {
                //图片上传的路径
                $this->imageFile->saveAs('uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
                return true;
            } else {
                return false;
            }
        }
    }
?>



